package com.ac.app.web.action.pick;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.ac.app.dm.*;
import com.ac.app.service.PickManager;
import com.caac.core.service.BaseManager;
import com.caac.core.util.ListMapClass;
import com.caac.core.web.action.BaseAction;
import com.caac.core.web.form.BaseForm;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright AgileCentury 2008</p>
 * <p>Company: AgileCentury </p>
 * @author <a href="mailto:ac@agilecentury.com">Agile</a>
 * @version 1.0
 */

public class RePickAction extends BaseAction {
    private ListMapClass entrys = new ListMapClass();

    protected ActionForward doExecute(ActionMapping mapping,
                                      BaseForm form,
                                      HttpServletRequest request,
                                      HttpServletResponse response)
            throws Exception {
        String valDate = request.getParameter("valDate");
        String valDate1 = request.getParameter("valDate1");
        String[] subs = request.getParameterValues("subs");
        PickManager pm = (PickManager) this.getBean("pickManager");
        BaseManager bm = this.getBaseManager();
        PickBase pbDm = pm.getPickBase();
        List peList = pm.getPickEntrys();
        for (int i = 0; i < peList.size(); i++) {
            PickEntry pe = (PickEntry) peList.get(i);
            entrys.addChild(pe.getId(), pe);
        }

        String where = "1=1 ";
        for(int j=0; j<subs.length;j++){
            where += " and sub_code='"+subs[j]+"'";
        }
            
        //List puList = m.getPickUrls(valDate);
        List puList = bm.getObjects(PickUrl.class, " pub_date between '"+valDate+"' and '"+valDate1+"'");
        for (int i = 0; i < puList.size(); i++) {
            PickUrl puDm = (PickUrl) puList.get(i);
            PickEntry peDm = (PickEntry) entrys.getChild(puDm.getEntryId());
            //List pkList = pm.getPickKeywords(peDm.getLanguageTp());
            String whereStr = where+ " and SUBSTRING(sub_code,1,2)='" + peDm.getLanguageTp() + "'";
            List pkList = bm.getObjects(PickKeyword.class, whereStr);            
            pm.savePickRecord(peDm, puDm, pkList, pbDm.getShotPath());
        }

        return forward(mapping);
    }
}
